package leetcode.code0313;

import java.util.PriorityQueue;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int nthSuperUglyNumber(int n, int[] primes) {
		if (n == 1)
			return 1;
		PriorityQueue<Integer> p = new PriorityQueue<>((a, b) -> a - b);
//		this.add(p, 1, primes);
		p.add(primes[0]);
		int ans = 0;
		while (n > 1) {
			ans = p.poll();
			this.add(p, ans, primes);
			n--;
		}
		return ans;
	}

	private void add(PriorityQueue<Integer> p, int num, int[] primes) {
		for (int prime : primes) {
			if (!p.contains(num * prime))
				p.add(num * prime);
			else {
				System.out.println(num + " " + prime + " " + num * prime);
			}
		}
	}

	@Override
	public void debug1() {
		HelpDebug.compare(32, this.nthSuperUglyNumber(12, HelpDebug.str2array3("[2,7,13,19]")));
	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();

	}

}
